cmake_minimum_required(VERSION 3.0)

project(pppoi)

enable_testing()

add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} --verbose)

include_directories(${PROJECT_SOURCE_DIR}/include)

SET(CMAKE_BUILD_TYPE "Debug")
#SET(CMAKE_CXX_FLAGS_DEBUG "$ENV{CXXFLAGS} -O0 -Wall -g2 -ggdb")
SET(CMAKE_CXX_FLAGS_DEBUG "$ENV{CXXFLAGS} -O3 -Wall")

set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib)

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/bin)

aux_source_directory(${PROJECT_SOURCE_DIR}/src SRC_DIR_SRCS)

# static librray
ADD_LIBRARY(pppoi STATIC ${SRC_DIR_SRCS})
# shared library
add_library(alianpppoi SHARED ${SRC_DIR_SRCS})

set_target_properties(alianpppoi PROPERTIES OUTPUT_NAME "pppoi")
set_target_properties(pppoi PROPERTIES CLEAN_DIRECT_OUTPUT 1)
set_target_properties(alianpppoi PROPERTIES CLEAN_DIRECT_OUTPUT 1)

set(LINKED_LIB pppoi ntl gmp pthread)

add_executable(she_run ${PROJECT_SOURCE_DIR}/test/test_she.cpp)
target_link_libraries(she_run ${LINKED_LIB})
add_test(test_she ${PROJECT_SOURCE_DIR}/bin/she_run)

add_executable(she2_run ${PROJECT_SOURCE_DIR}/test/test_she2.cpp)
target_link_libraries(she2_run ${LINKED_LIB})
add_test(test_she2 ${PROJECT_SOURCE_DIR}/bin/she2_run)

add_executable(timer_run ${PROJECT_SOURCE_DIR}/test/test_timer.cpp)
target_link_libraries(timer_run ${LINKED_LIB})
add_test(test_timer ${PROJECT_SOURCE_DIR}/bin/timer_run)

# Tools
add_executable(net_client_run ${PROJECT_SOURCE_DIR}/test/test_net_client.cpp)
target_link_libraries(net_client_run ${LINKED_LIB})
add_test(net_client ${PROJECT_SOURCE_DIR}/bin/net_client_run)

add_executable(net_server_run ${PROJECT_SOURCE_DIR}/test/test_net_server.cpp)
target_link_libraries(net_server_run ${LINKED_LIB})
add_test(net_server ${PROJECT_SOURCE_DIR}/bin/net_server_run)

# install static and shared library
install(TARGETS pppoi  alianpppoi DESTINATION lib)

# install head files
INSTALL (DIRECTORY ${CMAKE_SOURCE_DIR}/include/ DESTINATION include/pppoi FILES_MATCHING PATTERN "*.h*")
